<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class NickNameRule implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        //
        return preg_match(' /^[a-zA-Z][\w]{1,10}$|^([\x{4e0}-\x{9fa5}]|[\x{4e00}-\x{9fa5}a-z-A-Z\d_]){1,10}$/u', $value);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return ':attribute只能由数字、字母、中文汉字及下划线组成，不能包含特殊符号,长度在1到10位左右。';
    }
}
